package com.ihep;


public class Test {
 
    public static void main(String[] args) throws Exception {
//        String filepath="/Users/leeyi/workspace/ddg-ghbank/Data/key/";
 
//        String filepath = "/Users/leeyi/workspace/ddg2.1/Data/key/rsa_for_app_pub_key.pem";
//        RSAEncrypt.genKeyPair(filepath);
//         
//        System.out.println("--------------公钥加密私钥解密过程-------------------");
//        String plainText="ihep_公钥加密私钥解密";
//        //公钥加密过程
//        byte[] cipherData=RSAEncrypt.encrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile(filepath)),plainText.getBytes());
//        String cipher=Base64.encode(cipherData);
//        System.out.println(cipher);
        //私钥解密过程
//        byte[] res=RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile(filepath)), Base64.decode(cipher));
//        String restr=new String(res);
//        System.out.println("原文："+plainText);
//        System.out.println("加密："+cipher);
//        System.out.println("解密："+restr);
//        System.out.println();
         
//        System.out.println("--------------私钥加密公钥解密过程-------------------");
//        plainText="ihep_私钥加密公钥解密";
//        //私钥加密过程
//        cipherData=RSAEncrypt.encrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile(filepath)),plainText.getBytes());
//        cipher=Base64.encode(cipherData);
//        //公钥解密过程
//        res=RSAEncrypt.decrypt(RSAEncrypt.loadPublicKeyByStr(RSAEncrypt.loadPublicKeyByFile(filepath)), Base64.decode(cipher));
//        restr=new String(res);
//        System.out.println("原文："+plainText);
//        System.out.println("加密："+cipher);
//        System.out.println("解密："+restr);
//        System.out.println();
//       
        String filepath="/Users/leeyi/workspace/other/encryption/key/rsa_private_key.pem";
        System.out.println("---------------私钥签名过程------------------");
        String content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Document><header><channelCode>P2P001</channelCode><channelFlow>20160316175420006</channelFlow><channelDate>20160316</channelDate><channelTime>175420</channelTime><encryptData></encryptData><header><body><XMLPARA>7wPjJiSOm4ucZcU7lq0eqc37HWkJuz1bqjKpo6dgH11wqXi7ffFBzs2xmLOvYIhmAW6AVmky2uBvmIfhc0BTGDCQEbLUsjxZlzTrkHnodoBvOhLVjY/nWb+snb8izM6XuM9rtf2VYuAGkT8idBq+vMTh/sag+ccb7uiGHWmHUQno9bUCtcoA2TaGePIt9MkMIC6+QxRlda6mWzSoUZOj4w==</XMLPARA></body></Document>";
        String signstr=RSASignature.sign(content,RSAEncrypt.loadPrivateKeyByFile(filepath));
        System.out.println("签名原串："+content);
        System.out.println("签名串："+signstr);
        System.out.println();
//         
//        System.out.println("---------------公钥校验签名------------------");
//        System.out.println("签名原串："+content);
//        System.out.println("签名串："+signstr);
//         
//        System.out.println("验签结果："+RSASignature.doCheck(content, signstr, RSAEncrypt.loadPublicKeyByFile(filepath)));
//        System.out.println();
         
    }
}